﻿using System;
using HslCommunication.BasicFramework;

namespace HslCommunication.Core
{
	/// <summary>
	/// 按照字节错位的数据转换类<br />
	/// Data conversion class according to byte misalignment
	/// </summary>
	// Token: 0x02000128 RID: 296
	public class ReverseWordTransform : ByteTransformBase
	{
		/// <inheritdoc cref="M:HslCommunication.Core.ByteTransformBase.#ctor" />
		// Token: 0x0600194A RID: 6474 RVA: 0x0007F821 File Offset: 0x0007DA21
		public ReverseWordTransform()
		{
			base.DataFormat = DataFormat.ABCD;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.ByteTransformBase.#ctor(HslCommunication.Core.DataFormat)" />
		// Token: 0x0600194B RID: 6475 RVA: 0x0007F220 File Offset: 0x0007D420
		public ReverseWordTransform(DataFormat dataFormat) : base(dataFormat)
		{
		}

		/// <summary>
		/// 按照字节错位的方法
		/// </summary>
		/// <param name="buffer">实际的字节数据</param>
		/// <param name="index">起始字节位置</param>
		/// <param name="length">数据长度</param>
		/// <returns>处理过的数据信息</returns>
		// Token: 0x0600194C RID: 6476 RVA: 0x0007F834 File Offset: 0x0007DA34
		private byte[] ReverseBytesByWord(byte[] buffer, int index, int length)
		{
			bool flag = buffer == null;
			byte[] result;
			if (flag)
			{
				result = null;
			}
			else
			{
				result = SoftBasic.BytesReverseByWord(buffer.SelectMiddle(index, length));
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransInt16(System.Byte[],System.Int32)" />
		// Token: 0x0600194D RID: 6477 RVA: 0x0007F85F File Offset: 0x0007DA5F
		public override short TransInt16(byte[] buffer, int index)
		{
			return base.TransInt16(this.ReverseBytesByWord(buffer, index, 2), 0);
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransUInt16(System.Byte[],System.Int32)" />
		// Token: 0x0600194E RID: 6478 RVA: 0x0007F871 File Offset: 0x0007DA71
		public override ushort TransUInt16(byte[] buffer, int index)
		{
			return base.TransUInt16(this.ReverseBytesByWord(buffer, index, 2), 0);
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransByte(System.Int16[])" />
		// Token: 0x0600194F RID: 6479 RVA: 0x0007F884 File Offset: 0x0007DA84
		public override byte[] TransByte(short[] values)
		{
			byte[] inBytes = base.TransByte(values);
			return SoftBasic.BytesReverseByWord(inBytes);
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.TransByte(System.UInt16[])" />
		// Token: 0x06001950 RID: 6480 RVA: 0x0007F8A4 File Offset: 0x0007DAA4
		public override byte[] TransByte(ushort[] values)
		{
			byte[] inBytes = base.TransByte(values);
			return SoftBasic.BytesReverseByWord(inBytes);
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IByteTransform.CreateByDateFormat(HslCommunication.Core.DataFormat)" />
		// Token: 0x06001951 RID: 6481 RVA: 0x0007F8C4 File Offset: 0x0007DAC4
		public override IByteTransform CreateByDateFormat(DataFormat dataFormat)
		{
			return new ReverseWordTransform(dataFormat)
			{
				IsStringReverseByteWord = base.IsStringReverseByteWord
			};
		}

		/// <inheritdoc />
		// Token: 0x06001952 RID: 6482 RVA: 0x0007F8D9 File Offset: 0x0007DAD9
		public override string ToString()
		{
			return string.Format("ReverseWordTransform[{0}]", base.DataFormat);
		}
	}
}
